//
//  StoreCell.swift
//  Share
//
//  Created by admin on 2020/12/18.
//  Copyright © 2020 MBA. All rights reserved.
//

import SwiftUI

struct SroreCell: View {
    
    var store:Store
    var price:Float

    func getbandles() -> Float {
        return Float(store.num)*price - store.price*Float(store.num)
    }

    func getraido() -> Float {
        if store.price>0 {
            return ((price/store.price)-1.00)*100
        }else{
            return 0
        }
        
    }
    
    var body: some View {
        VStack {
            HStack{
                VStack{
                    Progress( percent: getraido())
                        .frame(width: 44, height: 44, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
                    Text("收益：\(getbandles() ,specifier: "%0.2f")")
                        .font(.system(size: 10))
                        .foregroundColor(getbandles()>0 ? .red_1 : .blue_2)
                }
                
                
                VStack(alignment: .leading){
                    Text("单价：\(store.price ,specifier: "%0.3f")")
                    Text("数量：\(store.num)")
                    Text("成本：\(store.getAllprice() ,specifier: "%0.2f")")
                    Text("买入时间：\(store.day ?? "--")")
                }
                .foregroundColor(.grey_2)
                .font(.system(size: 10))
               
            }

        }
        .padding(.all)
        .background(Color("background3"))
        .cornerRadius(4)
        .shadow(color: Color.shadow_1.opacity(0.5), radius: 2, x: 0, y: 0)
       
    }
}

struct StoreCell_Previews: PreviewProvider {
    static var previews: some View {
        SroreCell(store:Store._stores[0], price: 10.00)
    }
}
